from rest_framework import serializers

from orders.models import OrderInfo, OrderGoods, SKU


class OrderListSerializer(serializers.ModelSerializer):
    """获取订单列表数据"""
    class Meta:
        model = OrderInfo
        fields = ('order_id', 'create_time')


# 订单商品详情
class SKUInfoSerializer(serializers.ModelSerializer):

    class Meta:
        model = SKU
        fields = ('name', 'default_image_url')


# 订单SKU 列表
class SKUListSerializer(serializers.ModelSerializer):

    sku = SKUInfoSerializer()

    class Meta:
        model = OrderGoods
        fields = ('count', 'price', 'sku')


# 获取订单表详情数据
class OrderInfoSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField(label='下单用户')
    order_id = serializers.StringRelatedField(label='订单号')

    skus = SKUListSerializer(many=True)

    class Meta:
        model = OrderInfo
        # fields = '__all__'
        exclude = ('update_time', 'address')

